package com.Stream流;

import java.util.ArrayList;

public class StreamDemo {
    public static void main(String[] args) {
        //创建一个集合，存储多个字符串元素
        ArrayList<String> list = new ArrayList<String>();

        list.add("林青霞");
        list.add("张曼玉");
        list.add("王祖贤");
        list.add("柳岩");
        list.add("张敏");
        list.add("张无忌");

        //吧集合中所有以张开头的元素存储到一个新的集合
        ArrayList<String> zhangList = new ArrayList<String>();
        for (String s : list) {
            if (s.startsWith("张")) {
                zhangList.add(s);
            }
        }
        System.out.println(zhangList);

        //把张开头的集合长度为3的元素存储到新集合
        ArrayList<String> threeList = new ArrayList<String>();

        for (String s : zhangList) {
            if (s.length() == 3) {
                threeList.add(s);
            }
        }

        System.out.println(threeList);

        System.out.println("----------------------");

        //stream流改写
        list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3).forEach(s -> System.out.println(s));
    }
}
